import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)
/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index'),
        meta: { title: 'Dashboard', icon: 'dashboard', affix: true }
      }
    ]
  },
  // 基本资料
  {
    path: '/bd',
    component: Layout,
    redirect: '/bd/institution/group',
    name: 'BasicData',
    meta: {
      title: 'BasicData',
      icon: 'table'
    },
    children: [
      {
        path: 'institution',
        component: () => import('@/views/bd/institution/index'),
        name: 'Institution',
        meta: { title: 'institution' },
        redirect: '/bd/institution/group',
        children: [{
          path: 'group',
          component: () => import('@/views/bd/institution/group/index'),
          name: 'Group',
          meta: { title: 'group', icon: 'group' }
        },
        {
          path: 'organization',
          component: () => import('@/views/bd/institution/organization/index'),
          name: 'Organization',
          meta: { title: 'organization', icon: 'organization' }
        }]
      },
      {
        path: 'customerVendor',
        component: () => import('@/views/bd/customerVendor/index'),
        name: 'CustomerVendor',
        meta: { title: 'customerVendor' },
        redirect: '/bd/customerVendor/customers',
        children: [{
          path: 'customers',
          component: () => import('@/views/bd/customerVendor/customers/index'),
          name: 'Customers',
          meta: { title: 'customers', icon: 'customers' }
        },
        {
          path: 'vendors',
          component: () => import('@/views/bd/customerVendor/vendors/index'),
          name: 'Vendors',
          meta: { title: 'vendors', icon: 'vendors' }
        }]
      },
      {
        path: 'inventory',
        component: () => import('@/views/bd/inventory/index'),
        name: 'Inventory',
        meta: { title: 'inventory' },
        redirect: '/bd/inventory/paperLeng',
        children: [
          {
            path: 'paperLeng',
            component: () => import('@/views/bd/inventory/paperLeng/index'),
            name: 'paperLeng',
            meta: { title: 'paperLeng', icon: 'paperLeng' }
          },
          {
            path: 'paperdata',
            component: () => import('@/views/bd/inventory/paperData/index'),
            name: 'PaperData',
            meta: { title: 'paperData', icon: 'paperData' }
          }
        ]
      },
      {
        path: 'cartonSetting',
        component: () => import('@/views/bd/cartonSetting/index'),
        name: 'CartonSetting',
        meta: { title: 'cartonSetting' },
        redirect: '/bd/cartonSetting/cartonTypeSetting',
        children: [
          {
            path: 'cartonTypeSetting',
            component: () => import('@/views/bd/cartonSetting/cartonTypeSetting/index'),
            name: 'cartonTypeSetting',
            meta: { title: 'cartonTypeSetting', icon: 'cartonTypeSetting' }
          },
          {
            path: 'cartonProfile',
            component: () => import('@/views/bd/cartonSetting/cartonProfile/index'),
            name: 'cartonProfile',
            meta: { title: 'cartonProfile', icon: 'cartonProfile' }
          },
          {
            path: 'cartonProcess',
            component: () => import('@/views/bd/cartonSetting/cartonProcess/index'),
            name: 'cartonProcess',
            meta: { title: 'cartonProcess', icon: 'cartonProcess' }
          },
        ]
      }
    ]
  },
  // 人力资源
  {
    path: '/hr',
    component: Layout,
    redirect: '/hr/personnel/employee',
    name: 'HR',
    meta: {
      title: 'HR',
      icon: 'HR'
    },
    children: [
      {
        path: 'personnel',
        component: () => import('@/views/hr/personnel/index'),
        name: 'personnel',
        meta: { title: 'personnel' },
        redirect: '/hr/personnel/employee',
        children: [{
          path: 'employee',
          component: () => import('@/views/hr/personnel/employee/index'),
          name: 'employee',
          meta: { title: 'employee', icon: 'employee' }
        }]
      }
    ]
  },
  // 销售管理
  {
    path: '/salesManage',
    component: Layout,
    redirect: '/salesManage/cartonOrder',
    name: 'salesManage',
    meta: {
      title: 'salesManage',
      icon: 'sales'
    },
    children: [
      {
        path: 'cartonOrder',
        component: () => import('@/views/salesManage/cartonOrder/index'),
        name: 'cartonOrder',
        meta: { title: 'cartonOrder' },
        redirect: '/salesManage/cartonOrder',
        children: [{
          path: '',
          component: () => import('@/views/salesManage/cartonOrder/index'),
          name: 'cartonOrder',
          meta: { title: 'cartonOrder', icon: 'cartonOrder' }
        }]
      }
    ]
  },
  // 生产管理
  {
    path: '/produce',
    component: Layout,
    redirect: '/produce/cartonScheduling',
    name: 'ProduceManage',
    meta: {
      title: 'ProduceManage',
      icon: 'factory'
    },
    children: [
      {
        path: 'cartonScheduling',
        component: () => import('@/views/produce/cartonScheduling/index'),
        name: 'cartonScheduling',
        meta: { title: 'cartonScheduling' },
        redirect: '/produce/cartonScheduling',
        children: [{
          path: '',
          component: () => import('@/views/produce/cartonScheduling/index'),
          name: 'cartonScheduling',
          meta: { title: 'cartonScheduling', icon: 'cartonScheduling' }
        }]
      },
      {
        path: 'cartonWarehouse',
        component: () => import('@/views/produce/cartonWarehouse/index'),
        name: 'cartonWarehouse',
        meta: { title: 'cartonWarehouse' },
        redirect: '/produce/cartonWarehouse',
        children: [{
          path: '',
          component: () => import('@/views/produce/cartonWarehouse/index'),
          name: 'cartonWarehouse',
          meta: { title: 'cartonWarehouse', icon: 'cartonWarehouse' }
        }]
      }
    ]
  },
  // 库存管理
  {
    path: '/inventory',
    component: Layout,
    redirect: '/inventory/carton',
    name: 'InventoryManage',
    meta: {
      title: 'InventoryManage',
      icon: 'inventory'
    },
    children: [
      {
        path: 'carton',
        component: () => import('@/views/inventory/carton/index'),
        name: 'carton',
        meta: { title: 'carton' },
        redirect: '/inventory/carton',
        children: [
          {
            path: 'cartonLoadingUp',
            component: () => import('@/views/inventory/carton/cartonLoadingUp/index'),
            name: 'cartonLoadingUp',
            meta: { title: 'cartonLoadingUp', icon: 'cartonLoadingUp' }
          },
          {
            path: 'cartonDelivery',
            component: () => import('@/views/inventory/carton/cartonDelivery/index'),
            name: 'cartonDelivery',
            meta: { title: 'cartonDelivery', icon: 'cartonDelivery' }
          },
          {
            path: 'cartonReturn',
            component: () => import('@/views/inventory/carton/cartonReturn/index'),
            name: 'cartonReturn',
            meta: { title: 'cartonReturn', icon: 'cartonReturn' }
          },
          {
            path: 'InventoryDish',
            component: () => import('@/views/inventory/carton/InventoryDish/index'),
            name: 'InventoryDish',
            meta: { title: 'InventoryDish', icon: 'InventoryDish' }
          },
        ]
      },
      {
        path: 'vehicle',
        component: () => import('@/views/inventory/vehicle/index'),
        name: 'vehicle',
        meta: { title: 'vehicle' },
        redirect: '/inventory/vehicle',
        children: [
          {
            path: 'deliveryVehicle',
            component: () => import('@/views/inventory/vehicle/deliveryVehicle/index'),
            name: 'deliveryVehicle',
            meta: { title: 'deliveryVehicle', icon: 'deliveryVehicle' }
          },
          {
            path: 'deliveryRoute',
            component: () => import('@/views/inventory/vehicle/deliveryRoute/index'),
            name: 'deliveryRoute',
            meta: { title: 'deliveryRoute', icon: 'deliveryRoute' }
          },
          {
            path: 'seeCar',
            component: () => import('@/views/inventory/vehicle/seeCar/index'),
            name: 'seeCar',
            meta: { title: 'seeCar', icon: 'seeCar' }
          },
        ]
      }
    ]
  },
  // 财务管理
  {
    path: '/financial',
    component: Layout,
    redirect: '/financial/payable',
    name: 'FinancialManage',
    meta: {
      title: 'FinancialManage',
      icon: 'financial'
    },
    children: [
      {
        path: 'payable',
        component: () => import('@/views/financial/payable/index'),
        name: 'payableManage',
        meta: { title: 'payableManage' },
        redirect: '/financial/payable',
        children: [
          {
            path: 'payableStatement',
            component: () => import('@/views/financial/payable/payableStatement/index'),
            name: 'payableStatement',
            meta: { title: 'payableStatement', icon: 'payableStatement' }
          },
          {
            path: 'orderPay',
            component: () => import('@/views/financial/payable/orderPay/index'),
            name: 'orderPay',
            meta: { title: 'orderPay', icon: 'orderPay' }
          },
          {
            path: 'otherPay',
            component: () => import('@/views/financial/payable/otherPay/index'),
            name: 'otherPay',
            meta: { title: 'otherPay', icon: 'otherPay' }
          }
        ]
      },
      {
        path: 'receivable',
        component: () => import('@/views/financial/receivable/index'),
        name: 'receivableManage',
        meta: { title: 'receivableManage' },
        redirect: '/financial/receivable',
        children: [
          {
            path: 'receivableStatement',
            component: () => import('@/views/financial/receivable/receivableStatement/index'),
            name: 'receivableStatement',
            meta: { title: 'receivableStatement', icon: 'receivableStatement' }
          },
          {
            path: 'orderReceive',
            component: () => import('@/views/financial/receivable/orderReceive/index'),
            name: 'orderReceive',
            meta: { title: 'orderReceive', icon: 'orderReceive' }
          },
          {
            path: 'otherReceive',
            component: () => import('@/views/financial/receivable/otherReceive/index'),
            name: 'otherReceive',
            meta: { title: 'otherReceive', icon: 'otherReceive' }
          },
        ]
      }
    ]
  },
  // 系统设置
  {
    path: '/systemSetting',
    component: Layout,
    redirect: '/systemSetting/basicSetting',
    name: 'systemSetting',
    meta: {
      title: 'systemSetting',
      icon: 'setting'
    },
    children: [
      {
        path: 'basicSetting',
        component: () => import('@/views/systemSetting/basicSetting/index'),
        name: 'basicSetting',
        meta: { title: 'basicSetting' },
        redirect: '/systemSetting/basicSetting',
        children: [
          {
            path: '',
            component: () => import('@/views/systemSetting/basicSetting/index'),
            name: 'basicSetting',
            meta: { title: 'basicSetting', icon: 'basicSetting' }
          }
        ]
      },
      {
        path: 'organSetting',
        component: () => import('@/views/systemSetting/organSetting/index'),
        name: 'organSetting',
        meta: { title: 'organSetting' },
        redirect: '/systemSetting/organSetting',
        children: [
          {
            path: '',
            component: () => import('@/views/systemSetting/organSetting/index'),
            name: 'organSetting',
            meta: { title: 'organSetting', icon: 'organSetting' }
          }
        ]
      },
      {
        path: 'roleSetting',
        component: () => import('@/views/systemSetting/roleSetting/index'),
        name: 'roleSetting',
        meta: { title: 'roleSetting' },
        redirect: '/systemSetting/roleSetting',
        children: [
          {
            path: '',
            component: () => import('@/views/systemSetting/roleSetting/index'),
            name: 'roleSetting',
            meta: { title: 'roleSetting', icon: 'roleSetting' }
          }
        ]
      },
      {
        path: 'permissionSetting',
        component: () => import('@/views/systemSetting/permissionSetting/index'),
        name: 'permissionSetting',
        meta: { title: 'permissionSetting' },
        redirect: '/systemSetting/permissionSetting',
        children: [
          {
            path: '',
            component: () => import('@/views/systemSetting/permissionSetting/index'),
            name: 'permissionSetting',
            meta: { title: 'permissionSetting', icon: 'permissionSetting' }
          }
        ]
      },
      {
        path: 'operationRecord',
        component: () => import('@/views/systemSetting/operationRecord/index'),
        name: 'operationRecord',
        meta: { title: 'operationRecord' },
        redirect: '/systemSetting/operationRecord',
        children: [
          {
            path: '',
            component: () => import('@/views/systemSetting/operationRecord/index'),
            name: 'operationRecord',
            meta: { title: 'operationRecord', icon: 'operationRecord' }
          }
        ]
      },
      {
        path: 'InternetManagement',
        component: () => import('@/views/systemSetting/InternetManagement/index'),
        name: 'InternetManagement',
        meta: { title: 'InternetManagement' },
        redirect: '/systemSetting/InternetManagement',
        children: [
          {
            path: '',
            component: () => import('@/views/systemSetting/InternetManagement/index'),
            name: 'InternetManagement',
            meta: { title: 'InternetManagement', icon: 'InternetManagement' }
          }
        ]
      },
      {
        path: 'NoticeManagement',
        component: () => import('@/views/systemSetting/NoticeManagement/index'),
        name: 'NoticeManagement',
        meta: { title: 'NoticeManagement' },
        redirect: '/systemSetting/NoticeManagement',
        children: [
          {
            path: '',
            component: () => import('@/views/systemSetting/NoticeManagement/index'),
            name: 'NoticeManagement',
            meta: { title: 'NoticeManagement', icon: 'NoticeManagement' }
          }
        ]
      },
      {
        path: 'payOrderManage',
        component: () => import('@/views/systemSetting/payOrderManage/index'),
        name: 'payOrderManage',
        meta: { title: 'payOrderManage' },
        redirect: '/systemSetting/payOrderManage',
        children: [
          {
            path: '',
            component: () => import('@/views/systemSetting/payOrderManage/index'),
            name: 'payOrderManage',
            meta: { title: 'payOrderManage', icon: 'payOrderManage' }
          }
        ]
      },
    ]
  },
]

const createRouter = () =>
  new Router({
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}

export default router